<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>example03</title>
    <script type="text/javascript" src="../assests/js/vue.js"></script>
</head>
<body>
    <h1>$on & $once & $emit</h1>
    <hr>
    <div id="app">
        num:{{ num }}
        <p><button @click="add">add</button></p>
    </div>
    <p>
        <button onclick="reduce()">reduce</button>
        <button onclick="reduceOne()">reduceOne</button>
        <button onclick="off()">关闭reduce事件</button>
    </p>
    <script>
        var app = new Vue({
            el:"#app",
            data:{
                num:1
            },
            methods:{
                "add":function(){
                    this.num ++ ;
                }
            }
        });
        app.$on("reduce",function(){
            this.num--;
        });
        function reduce(){
            app.$emit("reduce");
        }
        app.$once("reduceOne",function(){
            this.num--;
        });
        function reduceOne(){
            app.$emit("reduceOne");
        }
        function off(){
            app.$off("reduce");
        }
    </script>
</body>
</html>